<template>
  <div class="md-paragraph" v-html="html"></div>
</template>

<script>

import { addClickListener } from "./MatSelection.js";

export default {
  props: ["html", "highlight"],
  data() {
    return {
    };
  },
  created() {
    //console.log("rendering html: ", this.html);
  },
  mounted() {
    let lines = this.$el.getElementsByClassName("line");
    for (let line of lines) {
      //this.addStatsSpan(line);
      // 给每句话添加一个选中事件
      addClickListener(this, line);
    }
  },
  methods: {
    addStatsSpan(line) {
      let stat = document.createElement("span");
      stat.classList.add("line-stat");
      let parent = line.parentNode;
      if (parent.lastChild == line) {
        parent.appendChild(stat);
      } else {
        parent.insertBefore(stat, line.nextSibling);
      }
    },
  }
};
</script>